package com.web.util.sql;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class IdGenerator {

	public static String getId(String prefix, String tableName, int seed) {
	
		String newId = null;
		PreparedStatement pStat = null;
		ResultSet rs = null;
		String sql = Messages.getString("IdGenerator.sql.select", tableName); //$NON-NLS-1$		
		
		try {
			pStat = DatabaseConnector.getConnection().prepareStatement(sql);
			rs = pStat.executeQuery();
			if (rs.next()) {
				newId = IdUtil.process(rs.getString("maxId"), prefix, seed);
			}			
			return newId;
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return null;
	}
	
}
